package tomasulo;
class Register {
	static final int DEFAULT_SIZE = 8;
	static final int DEFAULT_LDCLICKS = 2;
	static final int DEFAULT_STCLICKS = 2;
	
	int length;
	boolean busy[];
	int stationNo[];
	double val[];
	
	public void dispatch(int stationNo, double val) {
		System.out.println("[Register.dispatch]");
		for (int i = 0; i < length; i++)
			if (busy[i] && this.stationNo[i]==stationNo) {
				this.val[i] = val;
				this.stationNo[i] = -1;
				busy[i] = false;
			}
	}
	
	public void clear() {
		for (int i=0;i<length;i++) {
			busy[i] = false;
			stationNo[i] = -1;
			val[i] = 0;
		}
	}
	
	String[][] toStrings(){
		String[][] ret = new String[3][9];
                ret[0][0]="Busy";
                ret[1][0]="StationNo";
                ret[2][0]="Val";
		for(int i=0;i<8;i++){
			ret[0][i+1]=String .valueOf(busy[i]);
                        if(stationNo[i] == -1)
                                ret[1][i+1]="";
                        else
                            ret[1][i+1]=String .valueOf(stationNo[i]);
                        
			ret[2][i+1]=String.valueOf(val[i]);
		}
		return ret;
	}
	
	Register() {
		length = DEFAULT_SIZE;
		busy = new boolean[length];
		stationNo = new int[length];
		val = new double[length];
		
		clear();
	}
}